package com.guangfeng.yql.comm.controller;

import com.github.pagehelper.Page;
import com.guangfeng.yql.comm.bean.Code;
import com.guangfeng.yql.comm.bean.R;
import com.guangfeng.yql.comm.util.PageUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public class BaseController {


    public void startPage() {
        PageUtils.startPage();
    }

    public R page(List list) {
        if (list instanceof Page) {
            Page page = (Page) list;
            return R.comm(Code.SUCCESS, "查询成功", page, (int) page.getTotal());
        }
        return R.comm(Code.SUCCESS, "查询成功", list, list.size());
    }

    public R<?> rest(Integer result) {
        return result == 0 ? R.serve_error(null) : R.success(null);
    }

    public R<?> rest(Boolean result) {
        return result ? R.success(null) : R.serve_error(null);
    }


    public <T> R<T> ok(T data) {
        return R.success(data);
    }

}
